package at.fhooe.im440.pandora.events;

import java.util.ArrayList;

public class EventManager {
	

	private ArrayList<EventListener> eventListeners;
	
	private ArrayList<Event> pendingEvents;
	
	public EventManager(){
		setUpLists();
	}

	private void setUpLists() {
		eventListeners = new ArrayList<EventListener>();
		pendingEvents = new ArrayList<Event>();
		
	}

	public void addListener(EventListener e, String type) {
		eventListeners.add(e);
	}

	public void addEvent(Event e) {
		pendingEvents.add(e);	
	}

	public void removeListener(EventListener e) {
		if(eventListeners.contains(e))
		{
			eventListeners.remove(e);
		}
	}

	public void handleEvents() {
		for (int i = 0; i < eventListeners.size(); i++) 
		{
			for (int j = 0; j < pendingEvents.size(); j++) 
			{
				pendingEvents.get(j).processEvent(eventListeners.get(i));
				//.handleEvent(pendingEvents.get(j));
			}
		}
		pendingEvents.clear();
	}
}
